package com.yuexun.beilunpatient.ui.login.presenter.impl;


import com.yuexun.beilunpatient.ui.bean.BaseListEntity;
import com.yuexun.beilunpatient.ui.login.bean.LoginBean;
import com.yuexun.beilunpatient.ui.login.model.ILoginModel;
import com.yuexun.beilunpatient.ui.login.presenter.ILoginPresenter;
import com.yuexun.beilunpatient.ui.login.ui.view.ILoginView;

import org.kymjs.kjframe.ui.ViewInject;

import java.util.Map;

import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by chenss on 2018/3/14 0014.
 */

public class LoginPresenter implements ILoginPresenter {

    private ILoginView view;
    private ILoginModel model;

    //记录Log
//    private final Logger log = ProUtil.getLogger(LoginPresneter.class);

    public LoginPresenter(ILoginModel model, ILoginView view) {
        this.model = model;
        this.view = view;
    }

    @Override
    public void dologin(Map<String, String> praise) {
        model.loginInPatient(praise)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<BaseListEntity<LoginBean>>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        view.fail();
                        ViewInject.toast("登录失败");
                    }

                    @Override
                    public void onNext(BaseListEntity<LoginBean> loginBean) {
                        view.doInLogin(loginBean);
                    }
                });
    }
}
